package org.example.servletpractice.servlet;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "ServletLifeCycle", value = "/servletLifeCycle")
public class ServletLifeCycle extends HttpServlet {
    /*
    Servlet 初始化后调用 init () 方法。
    Servlet 调用 service() 方法来处理客户端的请求。
    Servlet 销毁前调用 destroy() 方法。
    最后，Servlet 是由 JVM 的垃圾回收器进行垃圾回收的。
    */

    public void init() {
        System.out.println("初始化");
    }

    public void service(ServletRequest request,
                        ServletResponse response)
            throws ServletException, IOException{
        System.out.println("处理客户端请求");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("doGet处理请求");
    }

    public void destroy() {
        System.out.println("Servlet销毁");
    }
}